package cn.dgut.training.dto.activity;

import cn.dgut.training.dto.BaseDTO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CouponDTO extends BaseDTO {

    private String name;

    private Integer couponType;

    private Integer couponStatus;

    public static QueryWrapper getWrapper(CouponDTO couponDTO){

        QueryWrapper<CouponDTO> queryWrapper=new QueryWrapper();

        if(!StringUtils.isBlank(couponDTO.getName())){
            queryWrapper.like("name",couponDTO.getName());
        }
        if(couponDTO.couponType!=null){
            queryWrapper.eq("coupon_type",couponDTO.getCouponType());

        }
        if(couponDTO.couponStatus!=null){
            queryWrapper.eq("coupon_status",couponDTO.getCouponStatus());

        }
        if(!StringUtils.isBlank(couponDTO.getOrderBy())){
            if("desc".equals(couponDTO.getSort())){
                queryWrapper.orderByDesc(couponDTO.getOrderBy());
            }else {
                queryWrapper.orderByAsc(couponDTO.getOrderBy());
            }

        }
        return queryWrapper;


    }
}
